package middleware

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"time"
)

//func ApiLogger() gin.HandlerFunc {
//	return func(ctx *gin.Context) {
//		// your custom format
//		t := time.Now()
//		ctx.Next()
//		fmt.Println("%s - [%s] \"%s %s %s %d %s \"%s\" %s\" %d\n",
//			param.ClientIP,
//			param.TimeStamp.Format(time.RFC1123),
//			param.Method,
//			param.Path,
//			param.Request.Proto,
//			param.StatusCode,
//			param.Latency,
//			param.Request.UserAgent(),
//			param.ErrorMessage,
//			time.Since(t).Microseconds(),
//		)
//	}
//}

func LoggerFormatter() gin.HandlerFunc {
	return gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
		// your custom format
		return fmt.Sprintf("%s - [%s] \"%s %s %s %d %s \"%s\" %s\"\n",
			param.ClientIP,
			param.TimeStamp.Format(time.DateTime),
			param.Method,
			param.Path,
			param.Request.Proto,
			param.StatusCode,
			param.Latency,
			param.Request.UserAgent(),
			param.ErrorMessage,
		)
	})
}
